package com.service.impl;


import com.dao.CourseContentMapper;
import com.domain.Course;
import com.domain.CourseLesson;
import com.domain.CourseSection;
import com.service.CourseContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CourseContentServiceImpl implements CourseContentService {

    @Autowired
    private CourseContentMapper courseContentMapper;

    /*
     * 根据课程id查询关联的章节信息及其关联的课时信息
     * */
    @Override
    public List<CourseSection> findSectionAndLessonByCourseId(Integer courseId) {
        return courseContentMapper.findSectionAndLessonByCourseId(courseId);
    }
    /*
     * 回显章节对应的课程信息
     * */
    @Override
    public Course findCourseByCourseId(Integer courseId) {
        return courseContentMapper.findCourseByCourseId(courseId);
    }
    /*
     * 新建章节
     * */
    @Override
    public void saveSection(CourseSection courseSection) {
        //补全信息
        courseSection.setStatus(1);
        Date date = new Date();
        courseSection.setCreateTime(date);
        courseSection.setUpdateTime(date);

        courseContentMapper.saveSection(courseSection);
    }
    /*
     * 修改章节
     * */
    @Override
    public void updateSection(CourseSection courseSection) {
        courseSection.setUpdateTime(new Date());

        courseContentMapper.updateSection(courseSection);
    }
    /*
     * 修改章节状态
     * */
    @Override
    public void updateSectionStatus(int id,int status) {
        //补全信息
        CourseSection courseSection = new CourseSection();
        courseSection.setId(id);
        courseSection.setStatus(status);
        courseSection.setUpdateTime(new Date());

        courseContentMapper.updateSectionStatus(courseSection);
    }
    /*
     * 新建课时
     * */
    @Override
    public void saveLesson(CourseLesson courseLesson) {
        //补全信息
        Date date = new Date();
        courseLesson.setCreateTime(date);
        courseLesson.setUpdateTime(date);

        courseContentMapper.saveLesson(courseLesson);
    }

    /*
     * 修改课时
     * */
    @Override
    public void updateLesson(CourseLesson courseLesson) {
        courseLesson.setUpdateTime(new Date());

        courseContentMapper.updateLesson(courseLesson);
    }
}
